﻿'===================================================================================
'功能說明:自行維護代理人資料,不由管理者維護,如同假單一樣.是由請假個人自行填寫請假單,再由人事部門查核.不是由人事部門填寫請假單
'建立人員: andy
'建立日期：2011/8/24
''===================================================================================
Imports System.Data
Partial Class WFAgentMaintain

    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName

        End If


    End Sub


    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim dd, dd1 As DateTime
        Try
            dd = DateTime.Parse(txtStartDate.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errStartDate"))
            mpIns.Show()
            Exit Sub

        End Try
        If dd < Now Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errStartDate"))
            mpIns.Show()
            Exit Sub
        End If

        Try
            dd1 = DateTime.Parse(txtEndDate.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            mpIns.Show()
            Exit Sub
        End Try
        If dd1 < Now Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            mpIns.Show()
            Exit Sub
        End If

        If dd > dd1 Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            mpIns.Show()
            Exit Sub
        End If
        Dim uDao As OAMS.DAO.UsersDAO = New OAMS.DAO.UsersDAO(hidbName.Value)
        If uDao.UserIsExist(txtAgent.Text) = False Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errAgent"))
            mpIns.Show()
            Exit Sub
        End If
        dbWFAgent.Insert()
        gvWFAgent.DataBind()
    End Sub

    Protected Sub btnAgent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAgent.Click
        PopupFormForAjax(btnAgent, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "Users", dbName, "1", txtAgent.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
        mpIns.Show()
    End Sub

    Protected Sub gvWFAgent_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvWFAgent.RowCommand
        If e.CommandName = "Agent" Then
            Dim btnAgent1 As LinkButton = gvWFAgent.Rows(gvWFAgent.EditIndex).FindControl("btnAgent1")
            Dim txtAgent1 As TextBox = gvWFAgent.Rows(gvWFAgent.EditIndex).FindControl("txtAgent1")

            PopupFormForAjax(btnAgent1, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "Users", dbName, "1", txtAgent1.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")

        End If
    End Sub

    Protected Sub gvWFAgent_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvWFAgent.RowUpdating
        Dim dd, dd1 As DateTime
        Dim txtStartDate1 As TextBox = gvWFAgent.Rows(e.RowIndex).FindControl("txtStartDate")
        Dim txtEndDate1 As TextBox = gvWFAgent.Rows(e.RowIndex).FindControl("txtEndDate")
        Dim txtAgent1 As TextBox = gvWFAgent.Rows(e.RowIndex).FindControl("txtAgent1")
        Try
            dd = DateTime.Parse(txtStartDate1.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errStartDate"))

            e.Cancel = True
            Exit Sub

        End Try
        If dd < Now Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errStartDate"))

            e.Cancel = True
            Exit Sub
        End If

        Try
            dd1 = DateTime.Parse(txtEndDate1.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            e.Cancel = True
            Exit Sub
        End Try
        If dd1 < Now Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            e.Cancel = True
            Exit Sub
        End If

        If dd > dd1 Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errEndDate"))
            e.Cancel = True
            Exit Sub
        End If
        Dim uDao As OAMS.DAO.UsersDAO = New OAMS.DAO.UsersDAO(hidbName.Value)
        If uDao.UserIsExist(txtAgent1.Text) = False Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errAgent"))
            e.Cancel = True
            Exit Sub
        End If
    End Sub
End Class
